package com.ccrfid.rmc6.pojo.dto.visitroom;

import com.ccrfid.rmc6.appconfig.jackson.CustomDouble4Serialize;
import com.ccrfid.rmc6.entity.business.visitroom.RoomVisitRuleEntity;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.util.List;

public class VisitRoomResultDto {
    private RoomVisitRuleEntity roomVisitRule;
    @JsonSerialize(using = CustomDouble4Serialize.class)
    private Double completionRate;
    private List<PrisonAreaDto> prisonAreaList;

    public RoomVisitRuleEntity getRoomVisitRule() {
        return roomVisitRule;
    }

    public void setRoomVisitRule(RoomVisitRuleEntity roomVisitRule) {
        this.roomVisitRule = roomVisitRule;
    }

    public Double getCompletionRate() {
        return completionRate;
    }

    public void setCompletionRate(Double completionRate) {
        this.completionRate = completionRate;
    }

    public List<PrisonAreaDto> getPrisonAreaList() {
        return prisonAreaList;
    }

    public void setPrisonAreaList(List<PrisonAreaDto> prisonAreaList) {
        this.prisonAreaList = prisonAreaList;
    }

    public void calcCompletionRate() {
        if (prisonAreaList != null && prisonAreaList.size() > 0) {
            double sum = 0.0;
            for (PrisonAreaDto areaDto : prisonAreaList) {
                sum += areaDto.getCompletionRate();
            }
            this.completionRate = sum / prisonAreaList.size();
        } else {
            this.completionRate = 0.0;
        }
    }
}
